package com.ykdl.member.kid.adapters;

import java.util.ArrayList;

import com.lidroid.xutils.BitmapUtils;
import com.ykdl.member.kid.R;
import com.ykdl.member.kid.adapters.MyLetterAdapter.ViewHolder;
import com.ykdl.member.kid.beans.MessageBean;
import com.ykdl.member.kid.beans.SystemMessageBean;
import com.ykdl.member.kid.doctor.DoctorInfoActivity;
import com.ykdl.member.kid.image.ImageOptions;
import com.ykdl.member.kid.image.ImageOptionsFactory;
import com.ykdl.member.kid.person.PersonCenterActivity;
import com.ykdl.member.kid.util.DateUtil;
import com.ykdl.member.kid.widget.AsyncImageView;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MessageAdapter1 extends BaseAdapter{
	private Context mContext ;
	private ArrayList<SystemMessageBean>  list;
	private BitmapUtils bitmapUtil ;
	public MessageAdapter1(Context context ){
		this.mContext = context;
		bitmapUtil = new BitmapUtils(mContext);
	}
	public void setlist(ArrayList<SystemMessageBean>  list) {
		this.list = list ;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if (list != null) {
			return list.size();
		} else {
			return 0;
		}
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		if (getCount() != 0) {
			return list.get(position-1);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null ;
		if (convertView==null) {
			convertView = RelativeLayout.inflate(mContext,
					R.layout.messageadapter1_item, null);
			holder = new ViewHolder();
			 holder.user_head =  (ImageView) convertView.findViewById(R.id.user_head);
			 holder.user_name=  (TextView) convertView.findViewById(R.id.user_name);
			 holder.count=  (TextView) convertView.findViewById(R.id.count);
			 holder.user_content=  (TextView) convertView.findViewById(R.id.user_content);
			 holder.user_time=  (TextView) convertView.findViewById(R.id.user_time);
			 convertView.setTag(holder);
		}else {
			holder = (ViewHolder)convertView.getTag();
		}
		if (null!=list.get(position).getLast().getFrom_actor().getAvatar_url()) {
			bitmapUtil.display(holder.user_head, list.get(position).getLast().getFrom_actor().getAvatar_url());
			
		}
		holder.user_name.setText(list.get(position).getLast().getFrom_actor().getDisplay_name());
		holder.count.setVisibility(View.VISIBLE);
		if (list.get(position).getCount()>99) {
			holder.count.setText("99+");
		}else if (list.get(position).getCount()==0) {
			holder.count.setVisibility(View.INVISIBLE);
		}else{
			holder.count.setText(list.get(position).getCount()+"");
		}
		holder.user_content.setText(list.get(position).getLast().getContext());
//		holder.user_time.setText(DateUtil.gettopicDate(list.get(position).getLast().getSend_time()));
		holder.user_time.setText(DateUtil.getMessageDate(list.get(position).getLast().getSend_time()));
		return convertView;
	}
	class ViewHolder {
		ImageView user_head;
		 TextView  user_name,count,
		user_content,user_time;
	}

}
